#!/home/tools/bin/64/python

import sys

if len(sys.argv) != 3:
    print "Usage: %s <file1> <file2>" %(sys.argv[0]) 
    sys.exit(1)

fileName1 = sys.argv[1]
fileName2 = sys.argv[2]

seperator = "\t"

def getKeyMultivalue(fileName):
    elements={}
    f = open(fileName,'r')
    for line in f:
        cols = line.rstrip('\n').split(seperator)
        key = cols[0]; # select key
        value = cols[1]; #select value
        if not key in elements:
            elements[key] = []
        elements[key].append(value)
    f.close()
    return elements

a = getKeyMultivalue(fileName1)
b = getKeyMultivalue(fileName2)

for x in a.keys():
    if x in b:
        for value1 in a[x]:
            for value2 in b[x]:
                print "%s%s%s%s%s" %(x, seperator, value1, seperator, value2)
        
